/**
 * @author hejl
 * @date on 2018/10/13.
 */
window.onload = function (ev) {
    topbar.hide();
};
var adminRole = roleCheck();
$('#dataTable').bootstrapTable({
    url: '/UserWithdrawBankController/queryUserWithdrawBankList',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100],
    clickToSelect: true,
    singleSelect: true,
    queryParams: queryParams,
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            //总页数
            "total": res.total,
            //数据
            "rows": res.rows
        };
    },
    onClickRow: function (row) {
        if (row.account != null && row.account != '') {
            $("#account_field"+row.id).html(row.account);
        }
    },
    columns: [[
        {
            checkbox: true
        },
        {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        },
        {
            title: '',
            field: 'id',
            visible: false,
            width: 100,
            align: 'center'
        }, {
            title: '会员编号',
            field: 'account',
            width: 100,
            align: 'center',
            formatter:function(v,o){
                return copyAddon(v) + (adminRole == 1 ? v :userAccountHidden(o.account,o.id));
            }
        }, {
            title: '会员姓名',
            field: 'name',
            width: 80,
            align: 'center'
        },
        {
            title: '银行卡号',
            field: 'bankNo',
            width: 50,
            align: 'center'
        },
        {
            align: 'center', field: 'bankAccountType', title: '银行类型'
        }, {
            title: '预留手机号',
            field: 'bankTelephone',
            width: 70,
            align: 'center'
        }, {
            title: '银行名',
            field: 'bankName',
            width: '80px',
            align: 'center'
        }, {
            title: '银行编码',
            field: 'bankCode',
            width: '80px',
            align: 'center'
        }, {
            title: '状态',
            field: 'isUse',
            width: 80,
            align: 'center',
            formatter: function (v, row, index) {
                return bankState[v];
            }
        },
        {
            title: '申请时间',
            field: 'gmtCreate',
            width: 200,
            align: 'center'
        },
        {
            title: '修改时间',
            field: 'gmtModified',
            width: 200,
            align: 'center'
        }
    ]]
});

$("#search").click(function () {
    $("#dataTable").bootstrapTable("refresh");
});

function queryParams(params) {
    return {
        pageSize: params.pageSize,
        pageNumber: params.pageNumber,
        state: $.trim($("#state").val()),
        account: $.trim($("#account").val())
    };
}

/**
 * 修改银行卡状态 0关闭 1开启
 */
function updateWithdrawBankState(state) {

    var rows = $('#dataTable').bootstrapTable("getSelections");
    if (rows === null || rows === '' || rows.length === 0) {
        layer.msg("请选择要操作的数据");
        return;
    }
    if (state === '' || state === null) {
        layer.msg("请选择要操作的数据");
        return;
    }

    var row = rows[0];
    $.post("UserWithdrawBankController/updateWithdrawBankState?bankId=" + row.id + "&state=" + state, null, function (data) {
        if (data.success) {
            $("#dataTable").bootstrapTable("refresh");
            $("#addWithdrawBankModel").modal("hide");
            layer.msg(data.message);
        } else {
            $("#addWithdrawBankModel").modal("hide");
            layer.msg(data.message);
        }
    });
}


//添加银行卡
function addWithdrawBankModel() {

    var rows = $('#dataTable').bootstrapTable("getSelections");
    if (rows === null || rows === '' || rows.length === 0) {
        layer.msg("请选择要操作的数据");
        return;
    }
    var account = rows[0].account;
    var bankId = rows[0].id;
    $("#addWithdrawBankForm").form("clear");
    $("#userAccount").val(account);
    $("#bankId").val(bankId);
    $("#bankAccountType").val("对私");
    $("#addWithdrawBankModel").modal("show");
}

/**
 * 添加银行卡信息
 */
function addWithdrawBank() {
    var account = $("#userAccount").val();
    var bankNo = $("#bankNo").val();
    var bankName = $("#bankName").val();
    if (account === null || account === "" || bankNo === null || bankNo === "" || bankName === "" || bankName === null) {
        layer.msg("必要信息为空");
        return
    }

    $.post("UserWithdrawBankController/addWithdrawBank", $("#addWithdrawBankForm").serialize(), function (data) {
        if (data.success) {
            $("#dataTable").bootstrapTable("refresh");
            $("#addWithdrawBankModel").modal("hide");
            layer.msg(data.message);
        } else {
            $("#addWithdrawBankModel").modal("hide");
            layer.msg(data.message);
        }
    });
}



